package cn.bocweb.spinning.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.GridView;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.bocweb.spinning.R;
import cn.bocweb.spinning.model.Bean.ReportTypeBean;
import cn.bocweb.spinning.util.DeviceUtil;
import cn.bocweb.spinning.view.adapter.ReportTypeAdapter;

public class ReportTypeDialog extends Dialog {

    ReportTypeAdapter mAdapter;
    OnSelectListener mOnSelectListener;
    List<ReportTypeBean.DataBean> mStringList;
    int selection = 1000;

    @Bind(R.id.select_community_list)
    GridView mSelectCommunityList;
    @Bind(R.id.btn_finish)
    Button mBtnFinish;

    public ReportTypeDialog(Context context) {

        super(context);

        mStringList = new ArrayList<>();

        mAdapter = new ReportTypeAdapter(getContext(), mStringList);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_report_type);
        ButterKnife.bind(this);
        setTitle("投诉类型");
        mSelectCommunityList.setAdapter(mAdapter);
    }

    @Override
    protected void onStart() {
        super.onStart();
        mAdapter.notifyDataSetChanged();
        mSelectCommunityList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                selection = position;
                mAdapter.setSelection(position);
                mAdapter.notifyDataSetChanged();
            }
        });
        mBtnFinish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (selection == 1000) {
                    DeviceUtil.MyToast(getContext(), "请选择一个投诉类型");
                } else {
                    mOnSelectListener.onClick(mStringList.get(selection).getTitle());

                }
            }
        });
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    public void setStringList(List<ReportTypeBean.DataBean> stringList) {
        mStringList.addAll(stringList);
    }

    public interface OnSelectListener {
        void onClick(String title);
    }

    public void setOnSelectListener(OnSelectListener onSelectListener) {
        mOnSelectListener = onSelectListener;
    }
}
